/*
xp_can.h
offer can bus transfor data api extern and data type define
designed by lunanting

-------------------
2022-02-16 14:38:53
create file
-------------------
*/
#ifndef XP_CAN_H
#define XP_CAN_H

#ifdef __cplusplus
extern "C" {
#endif

#include "aos/hal/can.h"
#include "aos/kernel.h"
#include "aos/list.h"


/*********************type define************/
//regist massage
typedef struct{
    void (*isr_rx_hanlder)(can_frame_t *,void *);
    int32_t (*customer_recv)(can_frameheader_t *,void *,const uint32_t);
    void *isr_rx_para;
}CAN_regist;

//can filter mask
typedef enum{
    can_filter_NO=0,
    
}CAN_filter;

//can bus
typedef struct{
    int id;     //CAN BUS ID
    aos_mutex_t send_mux;     //send mux
    can_frame_t *rx_buf;        //can recv frame buffer
    aos_queue_t rx_queue;       //can recv data queue
    slist_t dev_list;   //can dev list
    aos_mutex_t bus_mux;  //can bus mux
    can_dev_t can_config;   //can bus config
    CAN_filter filter;  //can master filter
    int init;   //init status,1=inited,0=no init
    can_frame_t tx_frame;   //tx frame
}CAN_bus;

//can device
typedef struct{
    int id;     //device id
    aos_sem_t dev_sem;  //device sem
    char rx_buf[8];   //device rx data buf
    int rx_len;     //device rx data len
    CAN_bus *bus;   //can bus msg
    slist_t next;   //device list
}CAN_dev;




/******************************api extern ***********************/
extern int xp_can_device_regist(CAN_dev *dev,int dev_id,int bus_id);    //device regist on can bus
extern int xp_can_device_unregist(CAN_dev *dev);    //device unregist on can bus

extern int xp_can_send(CAN_bus *can,int rtr,char *data,int len);    //send data on can bus
extern int xp_can_recive(CAN_bus *can,int wait,can_frame_t *recv_can_frame);    //recive data on can bus


#ifdef __cplusplus
}
#endif

#endif
// end of the file
